/*
 * Copyright (C) 2022 Huawei Technologies Co., Ltd.
 * Licensed under the Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain g_value1 copy of Mulan PSL v2 at:
 * http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 * PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#include <tee_ext_api.h>
#include <tee_log.h>
#include <securec.h>
#include <tee_arith_api.h>
#include <tee_mem_mgmt_api.h>
#include "test_arithmetic_api_base.h"

static uint8_t g_value1[] = {
    0x94, 0x4E, 0xD0, 0x6B, 0x75, 0x9F, 0xE1, 0x83, 0xB8, 0x40, 0xCB, 0x46, 0x5D, 0x7D, 0xAC, 0x35,
    0x71, 0xF2, 0x0A, 0x49, 0x3E, 0x7F, 0x65, 0x26, 0xB8, 0x6E, 0x5A, 0x59, 0x84, 0x47, 0xC4, 0x2B,
    0x53, 0xB6, 0x1D, 0xA9, 0x21, 0xC2, 0x5F, 0x0E, 0x8B, 0x1F, 0x8F, 0x15, 0xBF, 0x2D, 0x0D, 0x5D,
    0x4E, 0x33, 0xB2, 0x29, 0x9C, 0x4E, 0x01, 0xCC, 0x9F, 0x64, 0xD8, 0x56, 0xFB, 0xFD, 0xE7, 0xDC,
    0x37, 0xB4, 0x3C, 0xD5, 0xA1, 0x35, 0xD0, 0xBC, 0xF7, 0x2F, 0x52, 0x18, 0x5E, 0x11, 0xFD, 0x2B,
    0xAC, 0x89, 0xC4, 0x43, 0xE1, 0x84, 0x6B, 0xE1, 0x86, 0x53, 0xA4, 0x19, 0x90, 0x5B, 0xA3, 0xA6,
    0x2A, 0x51, 0xE2, 0x95, 0xFA, 0xF2, 0x54, 0xDA, 0x9B, 0x18, 0x3A, 0x95, 0x68, 0xFD, 0x20, 0xB0,
    0x6B, 0xEB, 0xD9, 0xD7, 0xD2, 0x76, 0x9E, 0x17, 0xCF, 0xD2, 0x68, 0x83, 0x8C, 0x6F, 0xA1, 0xD1,
    0x24, 0xF1, 0xB4, 0xC9, 0x86, 0x57, 0x0C, 0xAC, 0x68, 0xC1, 0x6B, 0x65, 0xF2, 0x4F, 0xB7, 0xBB,
    0xD7, 0xA6, 0xB8, 0xF9, 0x2A, 0x86, 0x16, 0x13, 0xE3, 0x9D, 0x82, 0x9F, 0x58, 0xCE, 0x60, 0x81,
    0x0C, 0x87, 0x87, 0xAD, 0x6C, 0x9C, 0x92, 0x95, 0x2C, 0x59, 0x87, 0x93, 0xF7, 0xEB, 0xA9, 0x8D,
    0x38, 0xBF, 0x78, 0xD9, 0x03, 0x4A, 0xA6, 0xFF, 0xA6, 0xF7, 0xE1, 0x01, 0x39, 0xB2, 0x1A, 0xC3,
    0xC7, 0xAF, 0x02, 0xFE, 0x2E, 0xBE, 0xC4, 0x40, 0x1E, 0xFC, 0x54, 0xC9, 0x32, 0xB7, 0x6F, 0xE8,
    0x19, 0xA6, 0x5B, 0xC1, 0xE6, 0x95, 0x45, 0xE6, 0x0C, 0x81, 0xA7, 0xC7, 0x76, 0x5F, 0xA9, 0x85,
    0x23, 0x96, 0x06, 0x30, 0xE4, 0x09, 0x31, 0x58, 0x72, 0xAE, 0x72, 0xEB, 0xEC, 0x88, 0xCA, 0x6A,
    0xD9, 0xB6, 0x68, 0xBA, 0x4E, 0x92, 0xD6, 0xE5, 0x77, 0x64, 0x5A, 0xE9, 0x4A, 0x65, 0x37, 0x27
};

static uint8_t g_value2[] = {
    0x52, 0xBD, 0x0E, 0x55, 0xE1, 0xD0, 0x2D, 0xA9, 0x6D, 0x08, 0x1C, 0x74, 0x44, 0x1B, 0x47, 0xEF,
    0x7B, 0x03, 0x45, 0x2F, 0x4C, 0x17, 0x41, 0x5A, 0x6C, 0x11, 0x02, 0x8E, 0x5D, 0x75, 0x64,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xA1, 0xAA, 0x82, 0xCB, 0x00, 0x6D, 0x0F, 0xCE, 0xF9, 0x26, 0xEF, 0x7D, 0x39, 0xD6,
    0x3E, 0x89, 0x91, 0x60, 0x1F, 0xC4, 0x14, 0x6F, 0xD4, 0x88, 0x00, 0x1F, 0x8C, 0x05, 0x81, 0xF3,
    0x0F, 0x41, 0x92, 0xFE, 0x03, 0x01, 0xAD, 0x80, 0xAA, 0xB5, 0x5B, 0x54, 0x32, 0x8B, 0xBB, 0x11
};

static uint8_t g_modulusVal[] = {
    0xAC, 0x09, 0xB8, 0xAC, 0x61, 0x73, 0x53, 0xF1, 0x4C, 0x1F, 0x9A, 0x44, 0x9A, 0xD6, 0x18, 0xF4,
    0x3C, 0x92, 0x45, 0x7A, 0xC1, 0xE4, 0xFD, 0x68, 0xCC, 0xBF, 0x89, 0x2E, 0x5E, 0x09, 0x0B, 0xE3,
    0x17, 0x61, 0x88, 0x20, 0xE3, 0x96, 0xE4, 0xAD, 0xC6, 0xB9, 0xC9, 0x02, 0x72, 0xC6, 0x99, 0x4C,
    0xFB, 0x8F, 0x99, 0xA6, 0x69, 0x9C, 0xBA, 0xD4, 0xF5, 0xDF, 0x4A, 0xBC, 0x0D, 0x9B, 0x9C, 0x05,
    0x7A, 0xC2, 0x93, 0xAB, 0x85, 0xD2, 0x6C, 0x4B, 0x01, 0x76, 0x66, 0x2D, 0xC4, 0x81, 0x64, 0x75,
    0xDA, 0x1E, 0x53, 0xAD, 0x00, 0xD6, 0x48, 0x3D, 0xB3, 0x0D, 0x74, 0x4A, 0xDA, 0x9E, 0xE5, 0x17,
    0xA3, 0xB1, 0xE3, 0x7E, 0xD6, 0x8F, 0x94, 0x67, 0x95, 0xDA, 0x29, 0x44, 0x33, 0xA9, 0x44, 0x96,
    0x9C, 0x2C, 0x89, 0xE3, 0x96, 0xBB, 0xD5, 0xF3, 0x29, 0x62, 0xAA, 0xAA, 0x83, 0xE2, 0xBD, 0x74,
    0xC4, 0x95, 0xA8, 0x2C, 0xB8, 0xD0, 0xF2, 0x8F, 0x9D, 0x33, 0xB4, 0x08, 0x52, 0xC5, 0xDF, 0xE1,
    0x32, 0x1C, 0x74, 0xB4, 0x6A, 0x30, 0xDF, 0xFE, 0x4E, 0x14, 0x86, 0x86, 0x75, 0xF8, 0xE5, 0x67,
    0x9A, 0x2D, 0x8A, 0xC4, 0x54, 0x36, 0xC2, 0xB3, 0xDB, 0xF6, 0x33, 0xF4, 0xD4, 0x8B, 0x9B, 0x4F,
    0x7D, 0xFF, 0x8F, 0x95, 0x39, 0x39, 0x60, 0xB2, 0x38, 0x3B, 0xF8, 0x06, 0xCC, 0xF4, 0x25, 0x00,
    0x6B, 0x11, 0xF2, 0xAA, 0x06, 0xC3, 0xEB, 0x3D, 0xFF, 0xF9, 0x8E, 0x89, 0xE2, 0x7A, 0x53, 0xA4,
    0x94, 0x23, 0x6C, 0x4A, 0xFB, 0xC6, 0x36, 0x51, 0xB0, 0xFD, 0xCC, 0x73, 0x53, 0x8F, 0xD2, 0x00,
    0x52, 0xFA, 0x2F, 0x34, 0xB8, 0x84, 0xAD, 0x32, 0x48, 0xB2, 0x49, 0x5C, 0xE5, 0xE2, 0xE0, 0xA1,
    0x9E, 0x76, 0x0D, 0x55, 0x0B, 0x3F, 0xFB, 0x28, 0x79, 0xCA, 0xE4, 0xF8, 0xCF, 0x8D, 0x52, 0x4D
};

static uint8_t g_checkModVal[] = {
    0x94, 0x4E, 0xD0, 0x6B, 0x75, 0x9F, 0xE1, 0x83, 0xB8, 0x40, 0xCB, 0x46, 0x5D, 0x7D, 0xAC, 0x35,
    0x71, 0xF2, 0x0A, 0x49, 0x3E, 0x7F, 0x65, 0x26, 0xB8, 0x6E, 0x5A, 0x59, 0x84, 0x47, 0xC4, 0x2B,
    0x53, 0xB6, 0x1D, 0xA9, 0x21, 0xC2, 0x5F, 0x0E, 0x8B, 0x1F, 0x8F, 0x15, 0xBF, 0x2D, 0x0D, 0x5D,
    0x4E, 0x33, 0xB2, 0x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58, 0x72, 0xAE, 0x72, 0xEB, 0xEC, 0x88, 0xCA, 0x6A,
    0xD9, 0xB6, 0x68, 0xBA, 0x4E, 0x92, 0xD6, 0xE5, 0x77, 0x64, 0x5A, 0xE9, 0x4A, 0x65, 0x37, 0x27,
};

static uint8_t g_checkAddVal[] = {
    0x3B, 0x02, 0x26, 0x14, 0xF5, 0xFC, 0xBB, 0x3B, 0xD9, 0x29, 0x4D, 0x76, 0x06, 0xC2, 0xDB, 0x30,
    0xB0, 0x63, 0x09, 0xFD, 0xC8, 0xB1, 0xA9, 0x18, 0x57, 0xBF, 0xD3, 0xB9, 0x83, 0xB4, 0x1C, 0xE6,
    0xEA, 0x80, 0xAE, 0xD0, 0x12, 0xA6, 0x95, 0xF6, 0xC1, 0x78, 0x0D, 0x12, 0xDF, 0xA3, 0xB1, 0xEB,
    0x25, 0x8B, 0x13, 0x9D, 0x56, 0x23, 0x52, 0xA5, 0x7A, 0x90, 0x13, 0x7D, 0xBF, 0x8B, 0xA3, 0x76,
    0x74, 0x96, 0xB4, 0xCA, 0x0F, 0xA4, 0xE6, 0x48, 0xE2, 0xB7, 0x9C, 0x99, 0x2A, 0xB2, 0xF6, 0xA1,
    0xC6, 0x1A, 0x38, 0xE4, 0x52, 0x82, 0xED, 0x99, 0x15, 0x71, 0xA7, 0x2B, 0x3B, 0xDE, 0x56, 0x01,
    0x7A, 0xB8, 0xA9, 0x68, 0x03, 0xE3, 0x23, 0x84, 0x57, 0x8F, 0xB5, 0x3D, 0x5B, 0x03, 0xB5, 0xE9,
    0x76, 0xE2, 0x8D, 0x52, 0x06, 0xC7, 0x14, 0xD8, 0x1C, 0x67, 0xE3, 0x55, 0x15, 0x84, 0x51, 0x4F,
    0x47, 0x25, 0xAB, 0x20, 0x7E, 0x12, 0xEE, 0xA4, 0xA7, 0x22, 0x52, 0xC9, 0x1E, 0xE3, 0x9A, 0x61,
    0x3F, 0x31, 0xA8, 0xE6, 0xCA, 0xB2, 0x9F, 0x6C, 0xE8, 0x5A, 0xF3, 0x8D, 0x17, 0xC6, 0x84, 0xA0,
    0xC8, 0x04, 0xB9, 0x74, 0x52, 0xCA, 0xA5, 0xCC, 0x1E, 0xCF, 0xAA, 0x40, 0x74, 0xE3, 0x3A, 0x28,
    0xD5, 0x44, 0x86, 0xEA, 0x7E, 0x8D, 0xEF, 0x68, 0xB7, 0x02, 0xBE, 0x6D, 0xAD, 0xAA, 0xCF, 0xEE,
    0x04, 0xF1, 0x33, 0xEA, 0x5E, 0xB9, 0x3C, 0x28, 0xC4, 0xAF, 0xC2, 0xF4, 0x8B, 0x04, 0xC3, 0xDD,
    0x8E, 0xA1, 0x91, 0x21, 0x6D, 0x9A, 0x10, 0x01, 0x6B, 0x52, 0xD4, 0x7B, 0x12, 0x4D, 0x11, 0x5B,
    0x0F, 0x25, 0x68, 0x5C, 0x4B, 0x48, 0x98, 0x95, 0xFE, 0x84, 0x29, 0xAE, 0x92, 0xAB, 0x6B, 0xBC,
    0x4A, 0x81, 0xEE, 0x63, 0x46, 0x54, 0x89, 0x3D, 0xA8, 0x4E, 0xD1, 0x44, 0xAD, 0x63, 0x9F, 0xEB
};

static uint8_t g_checkSubVal[] = {
    0x41, 0x91, 0xC2, 0x15, 0x93, 0xCF, 0xB3, 0xDA, 0x4B, 0x38, 0xAE, 0xD2, 0x19, 0x62, 0x64, 0x45,
    0xF6, 0xEE, 0xC5, 0x19, 0xF2, 0x68, 0x23, 0xCC, 0x4C, 0x5D, 0x57, 0xCB, 0x26, 0xD2, 0x5F, 0x8C,
    0xA5, 0x8A, 0x04, 0x61, 0x4D, 0x47, 0x43, 0x78, 0x8E, 0x0D, 0x48, 0x16, 0x2B, 0xEF, 0xCF, 0x82,
    0x7B, 0x4C, 0xB7, 0x0F, 0x78, 0xDB, 0xF6, 0x1E, 0xCE, 0x5A, 0x52, 0x74, 0x2A, 0xD4, 0x90, 0x3C,
    0x80, 0x0F, 0x31, 0x35, 0xAC, 0xF4, 0x4E, 0xE6, 0x0A, 0x30, 0xA1, 0x69, 0xCC, 0xEF, 0x9F, 0x3F,
    0xB8, 0xDA, 0xFB, 0xF6, 0x6F, 0xAF, 0xA1, 0xEC, 0x44, 0x28, 0x2C, 0xBD, 0x0A, 0x3A, 0x0C, 0x33,
    0x36, 0x39, 0x38, 0x45, 0x1B, 0x71, 0xF1, 0xC9, 0x48, 0xC6, 0x96, 0xA9, 0x43, 0x4D, 0x46, 0xE0,
    0xC4, 0xC8, 0x9C, 0x7A, 0x07, 0x6A, 0x51, 0x64, 0x59, 0xDA, 0x43, 0x07, 0x7F, 0x78, 0x34, 0xDE,
    0x3E, 0x28, 0x16, 0x45, 0xD5, 0xCA, 0x38, 0x24, 0x8D, 0x2C, 0xCF, 0xFA, 0x72, 0xF5, 0xF5, 0x35,
    0x3D, 0xFF, 0x54, 0x57, 0x20, 0x28, 0xAC, 0xBC, 0x90, 0xCB, 0x8B, 0x2B, 0x23, 0xDD, 0x56, 0xF9,
    0xB6, 0xDC, 0xCB, 0x22, 0x32, 0x37, 0xBC, 0xAA, 0x5D, 0xED, 0x30, 0xF2, 0xA6, 0x68, 0x7D, 0xA2,
    0x1E, 0x3A, 0xDB, 0x32, 0x4E, 0xCD, 0xFD, 0xE4, 0x5E, 0xB1, 0x0B, 0x8D, 0xF8, 0xC5, 0x40, 0x99,
    0x1F, 0x5A, 0xDF, 0x67, 0xF8, 0x00, 0x61, 0x19, 0x79, 0x4F, 0x58, 0x13, 0xF7, 0xEF, 0xC8, 0x4E,
    0x10, 0x87, 0xBA, 0x17, 0x63, 0xCA, 0x45, 0x78, 0xFC, 0xB2, 0xAE, 0xA0, 0x86, 0xE2, 0x6F, 0xAE,
    0xE5, 0x0C, 0x74, 0xD0, 0xC4, 0x45, 0x1C, 0xE8, 0x9E, 0x26, 0x72, 0xCC, 0x60, 0x83, 0x48, 0x77,
    0xCA, 0x74, 0xD5, 0xBC, 0x4B, 0x91, 0x29, 0x64, 0xCC, 0xAE, 0xFF, 0x95, 0x17, 0xD9, 0x7C, 0x16,
};

static uint8_t g_checkMulVal[] = {
    0x9B, 0xD1, 0x3A, 0x5B, 0x6E, 0x30, 0xC9, 0x43, 0x94, 0x61, 0xB8, 0xC0, 0x6A, 0xC5, 0xD1, 0x63,
    0x34, 0x3D, 0x0D, 0x10, 0x73, 0x5B, 0xAD, 0xE0, 0xDA, 0x9E, 0x25, 0x47, 0xD7, 0x82, 0xDF, 0xF7,
    0x2B, 0xEC, 0x74, 0x5A, 0xEB, 0xE9, 0x98, 0x43, 0xEA, 0x43, 0xFE, 0xD2, 0x2E, 0x1F, 0x30, 0x15,
    0x0B, 0x86, 0x30, 0x77, 0x16, 0x45, 0x16, 0x64, 0x7B, 0xBD, 0x3F, 0x96, 0x57, 0x24, 0x41, 0x86,
    0x06, 0xEB, 0x52, 0x0C, 0x22, 0xA8, 0xCF, 0x92, 0x20, 0x26, 0xC5, 0x33, 0x77, 0x65, 0xCC, 0x5D,
    0x8F, 0xBE, 0x31, 0xD4, 0x1E, 0x3E, 0x8E, 0x38, 0x81, 0x24, 0xAF, 0x60, 0xB2, 0x86, 0x54, 0x8C,
    0xAE, 0x39, 0x97, 0x35, 0xE6, 0x65, 0x3E, 0x6B, 0xEE, 0xC2, 0xCF, 0x18, 0x0A, 0xBA, 0xA3, 0xA6,
    0x66, 0x8E, 0x64, 0x41, 0x9E, 0x50, 0xD2, 0x3E, 0x73, 0xE5, 0x57, 0x08, 0x6B, 0xFE, 0xD9, 0xBA,
    0x62, 0x3B, 0x70, 0xCC, 0xAF, 0xB3, 0x3F, 0x67, 0x24, 0xBC, 0x32, 0x42, 0x48, 0xE3, 0x74, 0x0A,
    0x63, 0xB1, 0xF1, 0xAB, 0xAD, 0x20, 0xFE, 0xB8, 0x66, 0x22, 0x1B, 0x68, 0x45, 0xAB, 0x6E, 0xC9,
    0x0C, 0x84, 0x93, 0x43, 0xA9, 0x51, 0x7E, 0x2A, 0xDC, 0x8D, 0xF0, 0xF4, 0x41, 0x0C, 0x50, 0x6F,
    0x99, 0x3C, 0xC2, 0x71, 0xE6, 0xD9, 0xF6, 0xC5, 0x75, 0x42, 0xFA, 0x71, 0xF6, 0x3B, 0xA1, 0x67,
    0x04, 0xA3, 0xDA, 0x9D, 0x3F, 0xBD, 0x87, 0x90, 0x37, 0x14, 0xB6, 0x3A, 0x04, 0xA6, 0x0F, 0x8F,
    0xF9, 0xA4, 0xCC, 0xE2, 0x3D, 0x9C, 0x71, 0x6E, 0xFB, 0x26, 0x52, 0xD4, 0x7A, 0x3D, 0xE2, 0xEB,
    0xDD, 0x1C, 0x6E, 0xD5, 0xF4, 0x98, 0x96, 0x75, 0xE0, 0xA8, 0xE0, 0x9E, 0xAB, 0x6D, 0x9F, 0x4C,
    0x1F, 0x05, 0xDA, 0xD9, 0x74, 0x5F, 0x3C, 0x4A, 0x5B, 0x51, 0x89, 0x61, 0x7F, 0x15, 0x3C, 0x2C,
};

TEE_Result TestBigIntMod()
{
    tlogi("[%s] begin:", __FUNCTION__);
    TEE_Result ret = TEE_SUCCESS;
    TEE_BigInt *op = CreateBigInt(sizeof(g_value1), g_value1);
    TEE_BigInt *modulus = CreateBigInt(sizeof(g_modulusVal), g_modulusVal);
    TEE_BigInt *modDest = CreateBigInt(RESULT_SIZE, 0);
    TEE_BigInt *modCheck = CreateBigInt(sizeof(g_checkModVal), g_checkModVal);

    TEE_BigIntMod(modDest, op, modulus);
    if (TEE_BigIntCmp(modDest, modCheck) != 0) {
        tloge("BigIntMod failed.");
        ret = TEE_ERROR_GENERIC;
    }

    TEE_Free(op);
    TEE_Free(modulus);
    TEE_Free(modDest);
    TEE_Free(modCheck);
    tlogi("[%s] end. ret = 0x%x.", __FUNCTION__, ret);
    return ret;
}

TEE_Result TestBigIntAddAndSubMod()
{
    tlogi("[%s] begin:", __FUNCTION__);
    TEE_Result ret = TEE_SUCCESS;
    TEE_BigInt *op1 = CreateBigInt(sizeof(g_value1), g_value1);
    TEE_BigInt *op2 = CreateBigInt(sizeof(g_value2), g_value2);
    TEE_BigInt *modulus = CreateBigInt(sizeof(g_modulusVal), g_modulusVal);

    TEE_BigInt *addDest = CreateBigInt(RESULT_SIZE, 0);
    TEE_BigInt *addCheck = CreateBigInt(sizeof(g_checkAddVal), g_checkAddVal);
    TEE_BigIntAddMod(addDest, op1, op2, modulus);
    if (TEE_BigIntCmp(addDest, addCheck) != 0) {
        tloge("BigIntAddMod failed.");
        ret = TEE_ERROR_GENERIC;
        goto CLEANUP;
    }

    TEE_BigInt *subDest = CreateBigInt(RESULT_SIZE, 0);
    TEE_BigInt *subCheck = CreateBigInt(sizeof(g_checkSubVal), g_checkSubVal);
    TEE_BigIntSubMod(subDest, op1, op2, modulus);
    if (TEE_BigIntCmp(subDest, subCheck) != 0) {
        tloge("BigIntSubMod failed.");
        ret = TEE_ERROR_GENERIC;
    }
    TEE_Free(subDest);
    TEE_Free(subCheck);

CLEANUP:
    TEE_Free(op1);
    TEE_Free(op2);
    TEE_Free(modulus);
    TEE_Free(addDest);
    TEE_Free(addCheck);
    tlogi("[%s] end. ret = 0x%x.", __FUNCTION__, ret);
    return ret;
}

TEE_Result TestBigIntMulAndInvMod()
{
    tlogi("[%s] begin:", __FUNCTION__);
    TEE_Result ret = TEE_SUCCESS;
    TEE_BigInt *op1 = CreateBigInt(sizeof(g_value1), g_value1);
    TEE_BigInt *op2 = CreateBigInt(sizeof(g_value2), g_value2);
    TEE_BigInt *modulus = CreateBigInt(sizeof(g_modulusVal), g_modulusVal);

    TEE_BigInt *mulDest = CreateBigInt(RESULT_SIZE, 0);
    TEE_BigInt *mulCheck = CreateBigInt(sizeof(g_checkMulVal), g_checkMulVal);
    TEE_BigIntMulMod(mulDest, op1, op2, modulus);
    if (TEE_BigIntCmp(mulDest, mulCheck) != 0) {
        tloge("BigIntMulMod failed.");
        ret = TEE_ERROR_GENERIC;
        goto CLEANUP;
    }

    TEE_BigInt *squareDest = CreateBigInt(RESULT_SIZE, 0);
    TEE_BigInt *mulForsquareCheck = CreateBigInt(RESULT_SIZE, 0);
    TEE_BigIntSquareMod(squareDest, op1, modulus);
    TEE_BigIntMulMod(mulForsquareCheck, op1, op1, modulus);
    int32_t isSame = TEE_BigIntCmp(squareDest, mulForsquareCheck);
    TEE_Free(squareDest);
    TEE_Free(mulForsquareCheck);
    if (isSame != 0) {
        tloge("BigIntSquareMod failed.");
        ret = TEE_ERROR_GENERIC;
        goto CLEANUP;
    }

    TEE_BigInt *invDest = CreateBigInt(RESULT_SIZE, 0);
    TEE_BigInt *mulForinvCheck = CreateBigInt(RESULT_SIZE, 0);
    TEE_BigIntInvMod(invDest, op1, modulus);
    TEE_BigIntMulMod(mulForinvCheck, invDest, op1, modulus);
    if (TEE_BigIntCmpS32(mulForinvCheck, 1) != 0) {
        tloge("BigIntInvMod failed.");
        ret = TEE_ERROR_GENERIC;
    }
    TEE_Free(invDest);
    TEE_Free(mulForinvCheck);

CLEANUP:
    TEE_Free(op1);
    TEE_Free(op2);
    TEE_Free(modulus);
    TEE_Free(mulDest);
    TEE_Free(mulCheck);
    tlogi("[%s] end. ret = 0x%x.", __FUNCTION__, ret);
    return ret;
}

TEE_Result TestBigIntExpMod()
{
    tlogi("[%s] begin:", __FUNCTION__);
    TEE_Result ret = TEE_SUCCESS;
    uint32_t length = TEE_BigIntFMMContextSizeInU32(SIZE_256);
    TEE_BigIntFMMContext *bigIntFMMContext = TEE_Malloc(length * sizeof(TEE_BigIntFMMContext), 0);
    if (bigIntFMMContext == NULL) {
        tloge("CmdTEEBigIntInitFMMContext: TEE_Malloc returned NULL.");
        return TEE_ERROR_GENERIC;
    }

    const uint8_t modValue[] = {0x01, 0x31};
    TEE_BigInt *modulus = CreateBigInt(sizeof(modValue), (uint8_t *)modValue);
    TEE_BigIntInitFMMContext(bigIntFMMContext, length, modulus);

    const uint8_t desValue[] = "desValue";
    const uint8_t op1Value[] = {0x01, 0x01};
    const uint8_t op2Value[] = {0x01, 0x11};
    TEE_BigInt *des1 = CreateBigInt(sizeof(desValue), (uint8_t *)desValue);
    TEE_BigInt *des2 = CreateBigInt(sizeof(desValue), (uint8_t *)desValue);
    TEE_BigInt *op1 = CreateBigInt(sizeof(op1Value), (uint8_t *)op1Value);
    TEE_BigInt *op2 = CreateBigInt(sizeof(op2Value), (uint8_t *)op2Value);

    if (TEE_BigIntExpMod(des1, op1, op2, modulus, bigIntFMMContext) != TEE_SUCCESS) {
        tloge("TEE_BigIntExpMod failed with fmm context.");
        ret = TEE_ERROR_GENERIC;
        goto CLEAN_UP;
    }

    if (TEE_BigIntExpMod(des2, op1, op2, modulus, NULL) != TEE_SUCCESS) {
        tloge("TEE_BigIntExpMod failed with null context.");
        ret = TEE_ERROR_GENERIC;
        goto CLEAN_UP;
    }

    if (TEE_BigIntCmp(des1, des2) != 0) {
        tloge("TEE_BigIntExpMod failed for different result.");
        ret = TEE_ERROR_GENERIC;
    }

CLEAN_UP:
    TEE_Free(bigIntFMMContext);
    TEE_Free(modulus);
    TEE_Free(des1);
    TEE_Free(des2);
    TEE_Free(op1);
    TEE_Free(op2);

    tlogi("[%s] end. ret = 0x%x.", __FUNCTION__, ret);
    return ret;
}
